import request from '@/utils/request';
import { AllTradeMark, SaleAttrResponse, SkuInfo, SpuImages, SpuSaleAttrResponse, SpuValue, skuInfoResponse, spuResponse } from './type';

enum API {
  SPULIST_URL = '/admin/product/', // 获取所有spu
  ADDSPU_URL = '/admin/product/saveSpuInfo', // 新增spu
  EDITSPU_URL = '/admin/product/updateSpuInfo', // 修改spu
  DELETSPU_URL = '/admin/product/deleteSpu/', // 修改spu

  GETTRADeMARK_URL = '/admin/product/baseTrademark/getTrademarkList', // 获取所有的品牌
  GETSALES_URL = '/admin/product/baseSaleAttrList', // 获取所有的销售属性
  SPUIMAGE_URL = '/admin/product/spuImageList/', // 获取spu图片
  SPUSALEATTR_URL = '/admin/product/spuSaleAttrList/', // 获取spu销售属性

  SAVESKUINFO_URL = '/admin/product/saveSkuInfo', // 新增 sku
  SKUINFOLIST_URL = '/admin/product/findBySpuId/' // 已有 spu下售卖的商品sku
}

// 获取现有spu
export const reqSpuList = (page:number,limit:number,category3Id:number|string)=>request.get<any,spuResponse>(API.SPULIST_URL+`${page}/${limit}?category3Id=${category3Id}`)
// 获取所有的品牌
export const reqAllTrademarks = ()=>request.get<any, AllTradeMark>(API.GETTRADeMARK_URL)
// 获取所有的销属性
export const reqAllSales = ()=>request.get<any, SaleAttrResponse>(API.GETSALES_URL)
// 获取当前的spu 图片
export const reqSpuImage = (spuId:number)=>request.get<any, SpuImages>(API.SPUIMAGE_URL+spuId)
// 获取当前的 spu销售属性
export const reqSpuSaleAttr = (spuId:number)=>request.get<any, SpuSaleAttrResponse>(API.SPUSALEATTR_URL+spuId)

// 新增spu
// 编辑spu
export const reqAddSpu = (data:SpuValue)=>{
  if(data.id){
    return request.post<any, any>(API.EDITSPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}
export const reqDeletSpu = (id:number)=> request.delete<any, any>(API.DELETSPU_URL+id)
export const reqSaveSkuInfo = (data:SkuInfo)=> request.post<any, any>(API.SAVESKUINFO_URL, data)
export const reqSkuInfoList = (id:number)=> request.get<any, skuInfoResponse>(API.SKUINFOLIST_URL+id)